﻿<%@ Page Language="C#" %>
<style type="text/css">
.content{
      width:95%
    }
</style>
<script type="text/javascript">
 $(document).ready(function () {
   var orderID='<%=Request["orderid"]%>';
   var eBayUserID='<%=Request["ebayuserid"]%>';
   var msgID = '<%=Request["messageid"]%>';
   var mgsIDEx = '<%=Request["externalmessageid"]%>';
   var recipientID = '<%=Request["recipientid"]%>';
   var index = '<%=Request["index"]%>';
   var subject = '<%=Request["subject"]%>';

   $.getJSON(
     './MailHandler.ashx?act=q&id=0108&ebayuserid=' + eBayUserID + '&messageid=' + msgID,
     function (data) {
       if (data.retVal == 0) {
         if (data.retSrc && data.retSrc.Detail && data.retSrc.Detail.length > 0) {
           var detail = data.retSrc.Detail[0];
           $('#ddv-' + index).find('[title="from"]').text(detail.Sender);
           $('#ddv-' + index).find('[title="to"]').text(detail.SendToName);
           $('#ddv-' + index).find('[title="sendtime"]').text(detail.ReceiveDate);
           $('#ddv-' + index).find('[title="subject"]').text(detail.Subject);
           $('#ddv-' + index).find('[title="content"]').html(detail.Text.replace('<![CDATA[', '').replace(']]>', ''));
         }
       }
     });

   $('#ddv-' + index).find('[title="btnresponse"]').click(function () {
     var txt = $('#ddv-' + index).find('[name="content"]').val();

     $.post(
       './MailHandler.ashx?act=i&id=0001',
       { 'ebayuserid': eBayUserID, 'originalmsgid': msgID, 'externalmessageid': mgsIDEx, 'subject': 'Re: '+subject, 'body': txt, 'recipientid': recipientID, 'orderid': orderID, 'folderid': 8704 },
       function(jdata) {
         var data = $.parseJSON(jdata);
         if(data.retVal == 0) {
           alert('保存成功');
         }
         else {
           alert(data.retMsg);
         }
       });
   });

   $('#ddv-' + index).find('[title="btnsave"]').click(function () {
     var txt = $('#ddv-' + index).find('[name="content"]').val();
     $.post(
       './MailHandler.ashx?act=i&id=0001',
       { 'ebayuserid': eBayUserID, 'originalmsgid': msgID, 'externalmessageid': mgsIDEx, 'subject': 'Re: '+subject, 'body': txt, 'recipientid': recipientID, 'orderid': orderID, 'folderid': 8448 },
       function(jdata) {
         var data = $.parseJSON(jdata);
         if(data.retVal == 0) {
           alert('保存成功');
         }
         else {
           alert(data.retMsg);
         }
       });
   });

   $('#ddv-' + index).find('[title="btnattach"]').click(function () {
     alert('暂未实现');
   });
 });
</script>
<div style="margin-left:20px;">
  <div>From:<span title="from"></span></div>
  <div>To:<span title="to"></span></div>
  <div>Send Time:<span title="sendtime"></span></div>
  <div>Subject:<span title="subject"></span></div>
</div>
<div title="content" style="margin-left:20px;"></div>
<div>
  <textarea name="content" class="content" width="100%" rows="3"></textarea>
</div>
<div style="float: right;">
  <a title="btnresponse" class="easyui-linkbutton">回复</a>
  <a title="btnsave" class="easyui-linkbutton">保存</a>
  <a title="btnattach" class="easyui-linkbutton" data-options="disabled:'false'">附件</a>
</div>
